package com.lhy.admin.common.mvcplus.wrapper.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lhy.admin.common.mvcplus.entity.ComparatorEnum;
import com.lhy.admin.common.mvcplus.entity.DbField;
import com.lhy.admin.common.mvcplus.wrapper.AbstractSearchComparator;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BetweenSearchComparator extends AbstractSearchComparator {

    @Override
    public boolean valid(DbField dbField) {
        boolean valid = super.valid(dbField);
        return valid && splitStr(dbField.getValue()).length == 2;
    }

    @Override
    public void accept(QueryWrapper queryWrapper, DbField dbField) {
        String[] split = splitStr(dbField.getValue());
        if (split.length==2) {
            queryWrapper.between(dbField.getName(), split[0], split[1]);
        }
    }

    @Override
    public ComparatorEnum comparatorEnum() {
        return ComparatorEnum.BETWEEN;
    }
}
